package com.lt.basic.project.admin.controller.setting;

import com.lt.basic.project.admin.aop.Log;
import com.lt.basic.project.application.service.admin.setting.ISettingDictTypeService;
import com.lt.basic.project.common.aop.NotPower;
import com.lt.basic.project.common.core.AjaxResult;
import com.lt.basic.project.common.core.PageResult;
import com.lt.basic.project.common.validator.annotation.IDMust;
import com.lt.basic.project.pojo.validate.commons.IdsValidate;
import com.lt.basic.project.pojo.validate.commons.PageValidate;
import com.lt.basic.project.pojo.validate.admin.setting.DictTypeCreateValidate;
import com.lt.basic.project.pojo.validate.admin.setting.DictTypeUpdateValidate;
import com.lt.basic.project.pojo.vo.admin.setting.SettingDictTypeAllVo;
import com.lt.basic.project.pojo.vo.admin.setting.SettingDictTypeVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * 配置字典类型
 * @author LT
 */
@RestController
@RequestMapping("admin/setting/dict/type")
@Api(tags = "配置字典类型")
public class SettingDictTypeController {

    @Resource
    ISettingDictTypeService iSettingDictTypeService;

    /**
     * 根据字dictType典类型所有
     * @param dictType 字典类型
     * @return
     */
    @NotPower
    @GetMapping("/all")
    @ApiOperation(value="字典类型所有")
    public AjaxResult<List<SettingDictTypeAllVo>> all(String dictType) {
        return AjaxResult.success(iSettingDictTypeService.all(dictType));
    }

    /**
     * 字典类型列表
     * @param pageValidate
     * @param params
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value="字典类型列表")
    public AjaxResult<PageResult<SettingDictTypeVo>> list(@Validated PageValidate pageValidate,
                       @RequestParam Map<String, String> params) {
        PageResult<SettingDictTypeVo> list = iSettingDictTypeService.list(pageValidate, params);
        return AjaxResult.success(list);
    }

    /**
     * 字典类型详情
     * @param id
     * @return
     */
    @GetMapping("/detail")
    @ApiOperation(value="字典类型详情")
    public AjaxResult<SettingDictTypeVo> detail(@Validated @IDMust() @RequestParam("id") Long id) {
        SettingDictTypeVo vo = iSettingDictTypeService.detail(id);
        return AjaxResult.success(vo);
    }

    /**
     * 字典类型新增
     * @param createValidate
     * @return
     */
    @Log(title = "字典类型新增")
    @PostMapping("/add")
    @ApiOperation(value="字典类型新增")
    public AjaxResult<Object> add(@Validated @RequestBody DictTypeCreateValidate createValidate) {
        iSettingDictTypeService.add(createValidate);
        return AjaxResult.success();
    }

    /**
     * 字典类型编辑
     * @param updateValidate
     * @return
     */
    @Log(title = "字典类型编辑")
    @PostMapping("/edit")
    @ApiOperation(value="字典类型编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody DictTypeUpdateValidate updateValidate) {
        iSettingDictTypeService.edit(updateValidate);
        return AjaxResult.success();
    }

    /**
     * 字典类型删除
     * @param idsValidate
     * @return
     */
    @Log(title = "字典类型删除")
    @PostMapping("/del")
    @ApiOperation(value="字典类型删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdsValidate idsValidate) {
        iSettingDictTypeService.del(idsValidate.getIds());
        return AjaxResult.success();
    }

}
